package com.xpp.crowd.handler;

import com.xpp.crowd.api.MySQLRemoteService;
import com.xpp.crowd.entity.vo.ProtalTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import xpp.util.CrowdConstant;
import xpp.util.ResultEntity;

import java.util.List;

@Controller
public class PortalHandler {

    @Autowired
    MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/")
    public String showPortalPage(Model model){

        // 1. 调用MySQLRemoteService 提供的方法查询首页要显示的数据
        ResultEntity<List<ProtalTypeVO>> resultEntity= mySQLRemoteService.getProtalTypeProjectDataRemote();
        // 2.检测查询的结果
        String result = resultEntity.getResult();
        if(ResultEntity.SUCCESS.equals(result)){
            // 3.获取查询结果数据
            List<ProtalTypeVO> list = resultEntity.getData();
            // 4.存入模型
            model.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA,list);

        }
        return "portal";
    }
}
